package szk.exam.listener;
/*
 * @Description: 用来统计在线用户人数
 * @Author: 山志凯
 * @Date: 2021-06-15
 * @Time: 09:17
 */

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebListener
public class LoginOnline implements HttpSessionListener {
    private int count = -2;

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        //有人上线
        count++;
        se.getSession().setAttribute("onlineCount", count);
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
//有人下线
        count--;
        se.getSession().setAttribute("onlineCount", count);
    }
}
